import { createRouter, createWebHashHistory, createWebHistory } from "vue-router";
import HomeLayout from "@/components/mains/HomeLayout.vue";

const routes = [
  {
    path: "/autologin",
    name: "autologin",
    redirect: "/login",
  },

  {
    path: "/login",
    name: "login",
    component: () => import("../views/Login.vue"),
  },
  {
    path: "/error",
    name: "error",
    component: () => import("../views/Error.vue"),
  },

  {
    path: "/",
    redirect: "/WorkflowDesign",
  },

  {
    path: "/home",
    redirect: "/WorkflowDesign",
  },

  {
    path: "/WorkflowDesign",
    component: HomeLayout,
    meta: { isMenu: true, icon: "Cpu" },
    children: [
      {
        path: "",
        name: "流程设计",
        component: () => import("../views/WorkflowDesign.vue"),
        meta: { isMenu: true,isRequreManager: true, icon: "Share" },
      },
    ],
  },

  {
    path: "/WorkTask",
    component: HomeLayout,
    name: "流程审批",
    meta: { isMenu: true, icon: "Refresh" },
    children: [
      {
        path: "AllTasks",
        name: "所有审批",
        component: () => import("../views/WorkTask/AllTasks.vue"),
        meta: { isMenu: true,isRequreManager: true,  icon: "Operation" },
      },
      {
        path: "MyTasks",
        name: "我发起的",
        component: () => import("../views/WorkTask/MyTasks.vue"),
        meta: { isMenu: true, icon: "Position" },
      },
      {
        path: "ProcessedTasks",
        name: "我处理的",
        component: () => import("../views/WorkTask/ProcessedTasks.vue"),
        meta: { isMenu: true, icon: "Select" },
      },
      {
        path: "PeddingTasks",
        name: "待处理的",
        component: () => import("../views/WorkTask/PeddingTasks.vue"),
        meta: { isMenu: true, icon: "Loading" },
      },
    ],
  },

  {
    path: "/Plugin",
    component: HomeLayout,
    meta: { isMenu: true, icon: "Cpu" },
    children: [
      {
        path: "",
        name: "插件配置",
        component: () => import("../views/PluginConfig.vue"),
        meta: { isMenu: true,isRequreManager: true,  icon: "Cpu" },
      },
    ],
  },

  {
    path: "/components/:componentName?/:appid?",
    name: "components",
    component: () => import("../views/Comps/Components.vue"),
  },
  {
    path: "/comps",
    component: HomeLayout,
    meta: { isMenu: true, icon: "Menu" },  
    children: [
      {
        path: "",
        name: "小部件",
        component: () => import("../views/Comps/Index.vue"), 
        meta: { isMenu: true, icon: "Menu" },
      },
    ],
  },


  // 404 page must be placed at the end !!!
  {
    path: "/:pathMatch(.*)*",
    redirect: "/404",
  },
  {
    path: "/404",
    name: "notfound",
    component: () => import("../views/404.vue"),
  },
];
const router = createRouter({
  // history: createWebHistory(import.meta.env.BASE_URL),
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: routes,
});

export default router;

export const getRoutes = () => {
  return routes;
}
